package start;

import factory.IUserFactory;
import factory.NormalFactory;
import factory.RootFactory;
import user.NormalUser;
import user.ProxyUser;
import user.Root;
import user.User;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 32309
 * Date: 2025-07-17
 * Time: 19:32
 */
public class LibrarySystem {

    public static void main(String[] args) {
        start();
    }

    public static void start() {
        IUserFactory rootFactory = new RootFactory();
        User rootFactoryUser = rootFactory.createUser("然",1001);

        IUserFactory normalFactory = new NormalFactory();
        User normalFactoryUser1 = normalFactory.createUser("🤪",1002);
        User normalFactoryUser2 = normalFactory.createUser("🤡",1003);
        ProxyUser proxyUser1 = new ProxyUser(rootFactoryUser);
        ProxyUser proxyUser2 = new ProxyUser(normalFactoryUser1);
        ProxyUser proxyUser3 = new ProxyUser(normalFactoryUser2);
        ProxyUser user = getUsers(proxyUser1,proxyUser2,proxyUser3);
        while (true) {
            int choice = user.display();
            user.handleOperation(choice);
        }
    }

    public static ProxyUser getUsers (ProxyUser proxyUser1, ProxyUser proxyUser2,ProxyUser proxyUser3) {
        ProxyUser user = selectProxyRole(proxyUser1,proxyUser2,proxyUser3);
        while (user == null) {
            user = selectProxyRole(proxyUser1,proxyUser2,proxyUser3);
        }
        return user;
    }
    public static ProxyUser selectProxyRole(ProxyUser proxyUser1, ProxyUser proxyUser2, ProxyUser proxyUser3) {
        System.out.println("选择⻆⾊进⾏登录：");
        System.out.println("1.管理员(root)\n2.普通⽤⼾(滑稽🤪)\n3.普通⽤⼾(小丑🤡)\n4.退出系统\n");
        Scanner scanner = new Scanner(System.in);
        int choice = scanner.nextInt();
        switch (choice) {
            case 1:
                return proxyUser1;
            case 2:
                return proxyUser2;
            case 3:
                return proxyUser3;
            case 4:
                System.out.println("系统已退出..");
                System.exit(0);
                break;
            default:
                System.out.println("输入的无效操作，请重新选择：");
                return null;
        }
        return null;
    }
}
